<template>
	<view class="container">
		<scroll-view scroll-y>
			<view style="padding: 12px">
				<imgUpload
					@imgVideoList="imgVideoList"
					:imgVideoLists="imgVideoLists"
					:disabled="formData.disabled"
				/>
			</view>
			<view class="form-footer" v-if="!formData.disabled">
				<button class="form-footer-button" type="primary" @click="save">确定</button>
			</view>
			<view v-if="imgVideoLists.length === 0">
				<empty-block></empty-block>
			</view>
		</scroll-view>
	</view>
</template>

<script>
import { getFileList } from '@/api/common';
export default {
	data() {
		return {
			title: '上传拍照',
			formData: {},
			imgVideoLists: [],
			imgVideoListNew: [],
			delFileList: [],
			disabled: false,
		};
	},
	onLoad(option) {
		this.formData = JSON.parse(option.data);
	},
	onShow() {
		console.log('this.formData', this.formData);
		this.imgVideoLists = this.formData.fileList || [];
	},
	methods: {
		async getPhotoDetail(record) {
			const res = await getFileList({
				busId: '' + record.orderCode + '_' + record.id,
			});
			this.imgVideoLists = res.rows;
		},
		imgVideoList(img, video, delList) {
			this.imgVideoListNew = [...img, ...video];
			this.delFileList = [...this.delFileList, ...delList];
		},
		save() {
			let that = this;
			uni.showModal({
				content: '请确认，是否提交上传的图片、视频！',
				success: function (res) {
					if (res.confirm) {
						const eventChannel = that.getOpenerEventChannel();
						eventChannel.emit(
							'addPhotoOk',
							{
								fileList: that.imgVideoListNew,
							},
							that.formData,
						);
						setTimeout(() => {
							uni.navigateBack();
						}, 1000);
					} else if (res.cancel) {
						console.log('用户点击取消');
					}
				},
			});
		},
	},
};
</script>

<style lang="scss" scoped>
	.form-footer {
		margin-bottom: 30px;
	}
	.form-footer-button {
		width: 95%;
	}
</style>
